package com.zlh.rm.Exception;

public abstract class AbstractBaseException extends RuntimeException {
    /**
     * serial id.
     */
    private static final long serialVersionUID = 1L;
    /**
     * module code,this is defined in the document of user case.
     */
    private int moduleCode;
    /**
     * exception code,you should custom it by yourself.
     */
    private int exceptionCode;
    /**
     * error detail.
     */
    private String message;
    /**
     * message parameters.
     */
    private Object[] messageParams;

    /**
     * Constructor.
     * @param moduleCode
     *            code of module
     * @param exceptionCode
     *            code of custome exception
     * @param message
     *            verbose details of exception
     */
    protected AbstractBaseException(int moduleCode, int exceptionCode,
            String message) {
        super(message);
        this.moduleCode = moduleCode;
        this.exceptionCode = exceptionCode;
        this.message = message;
    }

    /**
     * Constructor with throwable.
     * @param moduleCode
     *            module code.
     * @param exceptionCode
     *            exception code
     * @param message
     *            error detail
     * @param t
     *            throwable instance.
     */
    protected AbstractBaseException(int moduleCode, int exceptionCode,
            String message, Throwable t) {
        super(message, t);
        this.moduleCode = moduleCode;
        this.exceptionCode = exceptionCode;
        this.message = message;
    }

    /**
     * Constructor with message parameters.
     * @param moduleCode
     *            module code
     * @param exceptionCode
     *            exception code
     * @param message
     *            error detail
     * @param params
     *            message parameters
     */
    protected AbstractBaseException(int moduleCode, int exceptionCode,
            String message, Object... params) {
        super(message);
        this.moduleCode = moduleCode;
        this.exceptionCode = exceptionCode;
        this.message = message;
        this.messageParams = params;
    }

    /**
     * Constructor only with message parameters.
     * @param params
     *            message parameters.
     */
    protected AbstractBaseException(Object... params) {
        this.messageParams = params;
    }

    /**
     * @return the moduleCode
     */
    public int getModuleCode() {
        return moduleCode;
    }

    /**
     * @param moduleCode
     *            the moduleCode to set
     */
    public void setModuleCode(int moduleCode) {
        this.moduleCode = moduleCode;
    }

    /**
     * @return the exceptionCode
     */
    public int getExceptionCode() {
        return exceptionCode;
    }

    /**
     * @param exceptionCode
     *            the exceptionCode to set
     */
    public void setExceptionCode(int exceptionCode) {
        this.exceptionCode = exceptionCode;
    }

    /**
     * set error message.
     * @param message
     *            error detail.
     */
    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }

    /**
     * @return the messageParams
     */
    public Object[] getMessageParams() {
        return messageParams;
    }

    /**
     * @param messageParams
     *            the messageParams to set
     */
    public void setMessageParams(Object[] messageParams) {
        this.messageParams = messageParams;
    }
}
